卸载低版本 MySQL
安装之前需要卸载系统预先安装的低版本的MySQL:1
2
3
4
5[root@localhost ~]
mysql-libs-5.1.71-1.el6.x86_64
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
安装 MySQL
1 | [root@localhost ~]# rpm -ivh MySQL-client-5.6.22-1.linux_glibc2.5.x86_64.rpm |
安装完毕:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
默认的配置文件目录:/usr/my.cnf
默认的登录随机密码:/root/.mysql_secret
修改 MySQL 字符集
1 | [root@localhost ~] |
添加如下内容:1
2
3
4
5[client]
default-character-set = utf8
[mysqld]
character-set-server = utf8
启动 MySQL
1 | [root@localhost ~]# service mysql start |
修改 Root 账号密码
先使用随机密码登录MySQL:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.22
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
利用 set 命令修改登录密码:1
2mysql> set password=password('123456');
Query OK, 0 rows affected (0.01 sec)
但是默认只是修改了 host 为 localhost 的root 账号信息:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user,host,password from user;
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | localhost.localdomain | *18F4A8EA07BDF2E0F5D54946F7CC4EDA905AB9DF |
| root | 127.0.0.1 | *18F4A8EA07BDF2E0F5D54946F7CC4EDA905AB9DF |
| root | ::1 | *18F4A8EA07BDF2E0F5D54946F7CC4EDA905AB9DF |
+------+-----------------------+-------------------------------------------+
4 rows in set (0.00 sec)
修改所有 root 账号:1
2
3
4
5
6mysql> update user set password=password('123456') where user = 'root';
Query OK, 3 rows affected (0.01 sec)
Rows matched: 4 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
添加新用户并赋权
1 | mysql> create user 'mysql'@'%' identified by '123456'; |
防火墙添加 MySQL 端口
编辑防火墙文件:1
[root@localhost ~]
添加如下内容:1
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重启防火墙服务:1
[root@localhost ~]# service iptables restart